package com.unionftech.content_login.ui.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.WindowManager
import android.widget.TextView
import com.unionftech.common.R.style
import com.unionftech.common.common.language.DynamicResourceManager
import com.unionftech.common.utils.Utils
import com.unionftech.content_login.R


class UFRegisterAccountTypeDialog(context: Context) : Dialog(context) {
    private val mTvIndividualAccount: TextView by lazy { findViewById(R.id.tv_individual_account) }
    private val mContext = context
    private var mCallBack: ((String) -> Unit)? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val contentView = LayoutInflater.from(mContext)
            .inflate(R.layout.layout_register_account_type_dialog, null)
        setContentView(contentView)
        setCancelable(true)
        setCanceledOnTouchOutside(true)
        setListener()
    }


    private fun setView() {
//        mTvIndividualAccount.text =
//            DynamicResourceManager.getString(mContext, string.individual_account)
        mTvIndividualAccount.isSelected = true
    }

    private fun setListener() {
        mTvIndividualAccount.setOnClickListener {
            mCallBack?.invoke(mTvIndividualAccount.text.toString())
            mTvIndividualAccount.isSelected = true
            dismiss()
        }
    }

    fun setCallBack(callBack: (String) -> Unit) {
        this.mCallBack = callBack
    }

    override fun onStart() {
        super.onStart()
        window?.decorView?.setPadding(0, 0, 0, 0)
        window?.attributes?.gravity = Gravity.BOTTOM
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.attributes?.windowAnimations = style.BottomDialogAnimation
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT
        )
        window?.also {
            Utils.setDialogNavigationBarTransparent(it)
        }
        setView()
    }
}